import com.yuanye.beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

/**
 * @Description Spring的创建和配置
 */

public class App {
    public static void main(String[] args) {
//        //1 .创建上下文需要配置spring配置信息（得到 Spring上下文）
//        ApplicationContext applicationContext =
//                new ClassPathXmlApplicationContext("spring.xml");
//
//        // 2.使用上下文对象获得一个bean
//        User user = (User) applicationContext.getBean("user");
//
//        // 3.使用 bean
//        user.saihi();

         //第二种获取Spring 上下文的方法是 BeanFactory
        //        BeanFactory beanFactory1 = new ClassPathXmlApplicationContext(
//                "spring.xml");
//        User user = (User) beanFactory.getBean("user");
        BeanFactory beanFactory = new XmlBeanFactory(
                new ClassPathResource("spring.xml")
        ); //这是最古老的方式
//        User user = beanFactory.getBean(User.class);
        User user = beanFactory.getBean("user",User.class);
        user.saihi();
    }
}
